﻿using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;
using CapturarObjetos.Objetos;
using CapturarObjetos.Nucleo;

namespace CapturarObjetos.Nucleo
{
    public class Botao
    {
        GameWindow Window;
        Texture2D image;
        public Vector2 position;
        public float scale = 1;
        Rectangle mouse_rect, button_rect;
        public bool isClicked;
        public bool isHoovering;
        public bool isVisible;

        

        public Botao(GameWindow Window, Texture2D image)
        {
            this.Window = Window;
            this.image = image;
            this.isVisible = false;
            this.isClicked = false;
        }

        public void Update(GameTime gameTime, MouseState mouse, MouseState mouse_old)
        {
            mouse_rect = new Rectangle((int)mouse.X, (int)mouse.Y, 5, 5);
            button_rect = new Rectangle((int)position.X, (int)position.Y, (int)(image.Width * scale), (int)(image.Height * scale));

            if (button_rect.Intersects(mouse_rect))
            {
                isHoovering = true;
                scale = 1.2f;
            }
            else
            {
                isHoovering = false;
                scale = 1.0f;
            }

            if ((mouse.LeftButton == ButtonState.Pressed && mouse_old.LeftButton != ButtonState.Pressed) && button_rect.Intersects(mouse_rect))
            {
                this.isClicked = true;
                
            }
            else
            {
                this.isClicked = false;
            }


        }

        public void Draw(GameTime gameTime, SpriteBatch spriteBatch)
        {
            if(this.isVisible)
                spriteBatch.Draw(image, position, new Rectangle(0, 0, image.Width, image.Height), Color.White, 0f, new Vector2(), scale, SpriteEffects.None, 0.5f);
        }

    }
}
